package com.ss.android.article.base.feature.update.activity;

import android.content.Context;

import com.ss.android.article.base.feature.update.a.c;
import com.ss.android.common.load.AsyncLoader.LoaderProxy;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

final class h implements LoaderProxy {
    private final g a;

    h(g arg1) {
        this.a = arg1;
    }

    public final Object doInBackground(Object key, Object param, Object extra) {
        return Boolean.valueOf(g.a(((Context) this.a.a), ((g.g$b) param)));
    }

    public final void onLoaded(Object key, Object param, Object extra, Object result) {
        int v0_2 = 0;
        g v2 = this.a;
        if (((Boolean) result).booleanValue()) {
            v2.x = ((g.g$b) param).c;
            v2.v = ((g.g$b) param).f;
            g.g$d v3 = v2.s;
            List v4 = ((g.g$b) param).h;
            List v0 = ((g.g$b) param).g;
            boolean v5 = ((g.g$b) param).d;
            boolean bingo = false;
            if (v4 == null || (v4.isEmpty())) {
                if (v0 != null && !v0.isEmpty()) {
                    bingo = true;
                } else {
                    v0_2 = 0;
                }
            } else {
                bingo = true;
            }

            if (bingo) {
                if (v5) {
                    v3.a.clear();
                    v3.b = v0;
                    v3.a.addAll(((Collection) v0));
                    v3.a.addAll(((Collection) v4));
                    v3.notifyDataSetChanged();
                    v0_2 = 1;
                } else {
                    ArrayList v5_1 = new ArrayList();
                    HashSet v6 = new HashSet();
                    Iterator v7 = v3.a.iterator();
                    while (v7.hasNext()) {
                        v6.add(Long.valueOf(((com.ss.android.article.base.feature.update.a.c) v7.next()).a));
                    }

                    Iterator v4_1 = v4.iterator();
                    while (v4_1.hasNext()) {
                        Object v0_1 = v4_1.next();
                        if (v6.contains(Long.valueOf(((c) v0_1).a))) {
                            continue;
                        }
                        v6.add(Long.valueOf(((c) v0_1).a));
                        ((List) v5_1).add(v0_1);
                    }

                    if (((List) v5_1).isEmpty()) {
                        v0_2 = 0;
                    } else {
                        v3.a.addAll(((Collection) v5_1));
                        v3.notifyDataSetChanged();
                        v0_2 = 1;
                    }
                }
            }

            if (v0_2 == 0) {
                v2.v = false;
            }
            v2.d();
        } else {
            if (((g.g$b) param).e == 12) {
                v2.t.switchToError(com.ss.android.article.browser.R.string.ss_error_no_connections);
            } else {
                v2.t.switchToError(com.ss.android.article.browser.R.string.ss_error_network_error);
            }
        }

        v2.y = null;
        v2.s.notifyDataSetChanged();
    }
}

